<?php 
	//timer pengecekan load page...
	include("inc/timer.php");
	$_start_timer = get_microtime();
	 
	//check protect1 jika session da tidak valid, balikin ke index.php
	//jika valid y biarin saja
	
	require_once("protect1.php");
	require_once("inc/connect.php");
	require_once("inc/settings.php");
	
	$_username = $reg_uname;
	$_semester = $_global_settings['semester']->value;
	$_tahun_ajaran = $_global_settings['tahun_ajaran']->value;
	$_level_settings = getLevelSettings($reg_level, $pdo);

	//$sql = "SELECT nama FROM biodata WHERE nrp = :reg_uname ";
	//$stmt = $pdo->prepare($sql);
	//$stmt->execute(array(':reg_uname' => $reg_uname )) or die("ERROR: " . implode(":", $stmt->errorInfo())); //reg jurusan dari protect1.php
	//$_data = $stmt->fetch(PDO::FETCH_OBJ);

?>
<!DOCTYPE html>
<html>
<head>
<title>Student Home !</title>
<link rel="stylesheet" type="text/css" href="css/reset_main.css">
<link rel="stylesheet" type="text/css" href="css/main.css">
<style type="text/css">
	body{ behavior:url(cssHoverFix.htc);}
	#div a { normal state }
	#div a:hover { alternative state }
</style>
</head>
<body>	
	<header id="main">
		<table id="header">
			<tr>
				<td class="header_logo_small"><a class="header_logo_small" href="#"></a></td>
				<td class="header_announce">
					<marquee style="letter-spacing:1px;marquee-speed:slow;">
						Nilai <strong>UTS</strong> Semester Gasal Periode 2012-2013 sudah keluar *sebagian. 
						Jika anda menemukan Bug / Kritik / Saran, silahkan Laporkan kepada ICT Sesegera mungkin. 
						Terima Kasih.
					</marquee>
				</td>
				<td class="header_user_name"><a class="header_user_name_a" href="#"><?php echo (strlen($_username) < 15 ? ucwords(strtolower($_username)) : ucwords(strtolower(substr($_username,0,15)))."..."); ?></a></td>
				<td class="header_user_photo">
					<a class="header_user_photo_a" href="#">
						<img class="header_user_photo_img" src="images/people/default.gif">
					</a>
				</td>
			</tr>
		</table>
	</header>
	<table class="board">
		<tr>
			<td class="sidebar">
				<div id="navigation">
					<ul class="top-level">
						<?php
							$basename_url = substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
							foreach($_level_settings->menu as $foreach){
								if ($basename_url == $foreach->url){$clicked = 'class="clicked"';}else{$clicked = '';}
								echo '<li><a href="'.$foreach->url.'" '.$clicked.'>'.$foreach->nama.'</a></li>';
							}							
						?>
					</ul>
				</div>
			</td>
			<td class="bigbox">
				<div class="banner"></div>
				<div class="content letter-spacing">	
					<h1>List Mahasiswa Perwalian</h1><br \>	
					<h2>Berikut dibawah ini adalah Daftar Mahasiswa yang anda terdaftar sebagai Dosen Walinya</h2>
					<div class="warning blue">
						<label>Ingat !</label>
						Untuk <span class="sign red border">Mendaftarkan</span> & <span class="sign red border">Membatalkan</span>, 
						Silahkan memilih <code>Mahasiswa</code>, setelah itu <span class="sign blue border">Mata kuliah</span> yang terdaftar oleh Mahasiswa tersebut.
						Serta jangan lupa untuk <span class="sign black border">menvalidkan KRS Mahasiswa</span> agar Mahasiswa dapat segera melakukan print out.
					</div><br \>
					<div align="center">
					
						<table class="data head">
							<tr>
								<td width="15%">Nama</td><td width="2%">:</td><td width="35%"><?php echo $_data->nama; ?></td><td width="15%">NIM</td><td width="2%">:</td><td width="35%"><?php echo $_username; ?></td>
							</tr>
							<tr>
								<td width="15%">Sesi / Periode</td><td width="2%">:</td><td width="35%"><?php echo $_semester.' - '.$_tahun_ajaran?></td>
								<td>Menyortir</td><td width="2%">:</td>
								<td>
									<select name="pilah" onchange="document.location.href='<?php echo $basename_url; ?>?pilah='+this.value;">
									  <option value="">-- Pilih --</option>
									  <option value="all">Semua Jurusan !</option>
									  <option value="111">Management</option>
									  <option value="112">Akuntansi</option>
									  <option value="212">Arsitektur</option>
									  <option value="311">Informatika</option>
									  <option value="611">Bahasa Tionghoa</option>
									  <option value="614">Bahasa Inggris</option>
									</select>
								</td>
							</tr>
						</table>
						<br />
						<table class="data body small">
						<thead>
							<tr>
								<th>NRP</th><th>Nama</th><th>Status</th><th>Act</th>
							</tr>
						</thead>
						<tbody>							
						<?php
							$count = 0; //using odd php for css2 browser and less
							$sql = "SELECT security.username as username_induk, 
							(SELECT nama FROM biodata WHERE nrp = username_induk LIMIT 1) as nama,
							(SELECT meta_value FROM user_metadata WHERE username = username_induk AND meta_key = 'validasi' LIMIT 1) as status,
							meta_value AS Data_Dosen_wali
							FROM security JOIN user_metadata ON user_metadata.username = security.username 
								AND (meta_key = 'dosen_wali' AND meta_value = :dosen_wali)
								
							UNION
							
							SELECT security.username AS username_induk, (
								SELECT nama
								FROM biodata
								WHERE nrp = username_induk
								LIMIT 1
							) AS nama, (
								SELECT meta_value
								FROM user_metadata
								WHERE username = username_induk
								AND meta_key =  'validasi'
								LIMIT 1
							) AS STATUS , (
								SELECT meta_value
								FROM user_metadata
								WHERE username = username_induk
								AND meta_key =  'dosen_wali'
								LIMIT 1
							) AS Data_Dosen_wali
							FROM SECURITY LEFT JOIN user_metadata ON user_metadata.username = security.username 
							WHERE LEVEL =1 
							group by username_induk asc
							having Data_Dosen_wali is NULL AND security.username LIKE :jurusan_dosen_wali
							";
							$stmt = $pdo->prepare($sql);
							$stmt->execute(array(':dosen_wali' => $_username 
												,':jurusan_dosen_wali' => substr($_username,0,3).'%'
												)); //reg jurusan dari protect1.php
//							var_dump($stmt->errorInfo());
							while($_data = $stmt->fetch(PDO::FETCH_OBJ)){ //fetch data to stdclass object
								$_data->url = "view_mk.php?kodemk=".$_data->kodemk;
								if($_data->status != 1 && $_data->status != 2 && $_data->status != 3){
									$_data->status = 0;
								}
								switch($_data->status){
									case 0 : { $_data->status_ = 'Tahap KRS'; break; }
									case 1 : { $_data->status_ = 'Tahap Validasi'; break; }
									case 2 : { }
									default : { $_data->status_ = '<code>Telah VALID</code>'; break; }
								}
								?>
									<tr onclick="document.location.href='<?php echo $_data->url;?>';" <?php echo ( ($count % 2) == 0 ? 'class="odd"' : ''); ?>>
										<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->username_induk; ?></a></td>														
										<td align="left"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->nama; ?></a></td>
										<td class="center"><a id="block" href="<?php echo $_data->url;?>"><?php echo $_data->status_; ?></a></td>
										<td class="center"><a id="block" href="<?php echo $_data->url;?>">????</a></td>
									</tr>
								<?php
								$count++;
							}
						?>
						</tbody>
						<tfoot>
							<tr>
								<td>TOTAL</td><td style="text-align:left;"><span class="sign black big border"><?php echo $count; ?></span> Mata Kuliah</td><td colspan="5"></td>
							</tr>
						</tfoot>
						</table>
						<br \>
					
					<div style="padding-bottom:50px;"></div>
				</div>
			</td>
		</tr>
	</table>
	<footer id="main">
	  <div><a href="http://www.widyakartika.ac.id/perpustakaan">Perpustakaan Online</a> | <a href="http://krs.widyakartika.ac.id/">KRS Online</a></div>
	  <div>Copyright &copy; 2012. <a href="http://www.widyakartika.ac.id">Universitas Widya Kartika</a> & <a href="#">Labkom ICT</a> - All rights reserved</div>
		<?php
			$_finish_timer = get_microtime();
			echo 'Page generated in '.round(($_finish_timer - $_start_timer), 4).' seconds.';
		?>
	</footer>
</body>
